home *** CD-ROM | disk | FTP | other *** search
/ Gamers Delight 2 / Gamers Delight 2.iso / Aminet / game / board / UChessSrc.lha / nondsp.c < prev    next >
C/C++ Source or Header  |  1994-06-29  |  24KB  |  1,153 lines

  1. /*
  2.  * nondsp.c - UNIX & MSDOS NON-DISPLAY, AND CHESSTOOL interface for Chess
  3.  *
  4.  * Copyright (c) 1988,1989,1990 John Stanback
  5.  * Copyright (c) 1992 Free Software Foundation
  6.  *
  7.  * This file is part of GNU CHESS.
  8.  *
  9.  * GNU Chess is free software; you can redistribute it and/or modify
  10.  * it under the terms of the GNU General Public License as published by
  11.  * the Free Software Foundation; either version 2, or (at your option)
  12.  * any later version.
  13.  *
  14.  * GNU Chess is distributed in the hope that it will be useful,
  15.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  17.  * GNU General Public License for more details.
  18.  *
  19.  * You should have received a copy of the GNU General Public License
  20.  * along with GNU Chess; see the file COPYING.  If not, write to
  21.  * the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
  22.  */
  23.  
  24. #include <ctype.h>
  25. #include <signal.h>
  26.  
  27. #ifdef AMIGA
  28. void mysprintf(char *,char *,int);
  29. void mysprintf4(char *,char *,int);
  30. void mysprintf3(char *,char *,int,int);
  31. void algbr2 (short, short, short);
  32. #define __USE_SYSBASE
  33. #include <exec/types.h>
  34. #include <exec/exec.h>
  35. #include <proto/exec.h>
  36. #include <proto/dos.h>
  37. #include <proto/graphics.h>
  38. #include <proto/intuition.h>
  39. #endif
  40.  
  41. char __far HintString[80];
  42.  
  43.  
  44. #define SIGQUIT SIGINT
  45.  
  46. #include "gnuchess.h"
  47. #ifdef MSDOS
  48. #include <dos.h>
  49. #include <conio.h>
  50. #include <stdlib.h>
  51. #include <string.h>
  52. #include <time.h>
  53. #else
  54. #include <dos.h>
  55. #include <stdlib.h>
  56. #include <string.h>
  57. #include <time.h>
  58. /*
  59. #include <sys/param.h>
  60. #include <sys/types.h>
  61. #include <sys/file.h>
  62. #include <sys/ioctl.h>
  63. */
  64. #endif
  65.  
  66. extern int __aligned thinkahead;
  67.  
  68. extern INTSIZE __aligned amigaboard[64],amigacolor[64];
  69. extern short int ISZERO;
  70. char __aligned __far IllegalString[40];
  71. extern int AmigaStarted;
  72. extern int __aligned global_tmp_score;
  73. extern int __aligned previous_score;
  74. int __aligned IllegalMove=0;
  75. int __aligned Mate=0;
  76. int __aligned DrawnGame=0;
  77. char __far __aligned MateString[40]={0};
  78. extern long OrigResponse;
  79.  
  80. #ifdef DEBUG
  81. INTSIZE int __aligned debuglevel = 0;
  82.  
  83. #endif /* DEBUG */
  84. unsigned INTSIZE int __aligned MV[MAXDEPTH];
  85. int __aligned MSCORE;
  86.  
  87. #if defined CHESSTOOL || defined XBOARD
  88. INTSIZE int __aligned chesstool = 1;
  89.  
  90. #else
  91. INTSIZE int __aligned chesstool = 0;
  92.  
  93. #endif /* CHESSTOOL */
  94. extern char __aligned mvstrhint[8][8];
  95. extern char mvstr[8][8];
  96. int __aligned mycnt1, mycnt2;
  97. char __aligned *DRAW;
  98. extern char *InPtr;
  99. extern INTSIZE int pscore[];
  100.  
  101. void mysprintf4(ostr,fstr,num)
  102. char *ostr,*fstr;
  103. int num;
  104. { // formats string "Tgt:%d xxx"
  105.  
  106.  int index;
  107.  int thou,hun,ten,one,rem;
  108.  
  109.  
  110.  ostr[0] = fstr[0];
  111.  ostr[1] = fstr[1];
  112.  ostr[2] = fstr[2];
  113.  ostr[3] = fstr[3];
  114.  ostr[4] = 0;
  115.  if (num < 0) 
  116.   {
  117.    num = -num;
  118.    index = 5;
  119.    strcat(ostr,"-");
  120.   }
  121.  else
  122.   {
  123.    index = 4;
  124.   }
  125.  thou = num / 1000;
  126.  rem = num-(num / 1000)*1000;
  127.  hun = (rem / 100);
  128.  rem = rem-(hun * 100);
  129.  ten = rem / 10;
  130.  rem = rem-(ten * 10);
  131.  one = rem;
  132.  if (thou)
  133.   {
  134.    ostr[index++] = thou+'0';
  135.   }
  136.  if ((hun)||(thou))
  137.   {
  138.    ostr[index++] = hun+'0';
  139.   }
  140.  if ((ten)||(hun)||(thou))
  141.   {
  142.    ostr[index++] = ten+'0';
  143.   }
  144.  ostr[index++] = one+'0';
  145.  ostr[index] = 0;
  146.  strcat(ostr,&fstr[6]);
  147. }
  148.  
  149. void mysprintf3(ostr,fstr,num,num2)
  150. char *ostr,*fstr;
  151. int num,num2;
  152. { // formats string "D%d S%d "
  153.  
  154.  int index;
  155.  int thou,hun,ten,one,rem;
  156.  
  157.  
  158.  ostr[0] = fstr[0]; // get the D
  159.  ostr[1] = 0;
  160.  if (num < 0) 
  161.   {
  162.    num = -num;
  163.    index = 2;
  164.    strcat(ostr,"-");
  165.   }
  166.  else
  167.   {
  168.    index = 1;
  169.   }
  170.  thou = num / 1000;
  171.  rem = num-(num / 1000)*1000;
  172.  hun = (rem / 100);
  173.  rem = rem-(hun * 100);
  174.  ten = rem / 10;
  175.  rem = rem-(ten * 10);
  176.  one = rem;
  177.  if (thou)
  178.   {
  179.    ostr[index++] = thou+'0';
  180.   }
  181.  if ((hun)||(thou))
  182.   {
  183.    ostr[index++] = hun+'0';
  184.   }
  185.  if ((ten)||(hun)||(thou))
  186.   {
  187.    ostr[index++] = ten+'0';
  188.   }
  189.  ostr[index++] = one+'0';
  190.  ostr[index++] = fstr[3];
  191.  ostr[index++] = fstr[4];
  192.  
  193.  if (num2 < 0)
  194.   {
  195.    num2 = -num2;
  196.    ostr[index++] = '-';
  197.   }
  198.  thou = num2 / 1000;
  199.  rem = num2-(num2 / 1000)*1000;
  200.  hun = (rem / 100);
  201.  rem = rem-(hun * 100);
  202.  ten = rem / 10;
  203.  rem = rem-(ten * 10);
  204.  one = rem;
  205.  if (thou)
  206.   {
  207.    ostr[index++] = thou+'0';
  208.   }
  209.  if ((hun)||(thou))
  210.   {
  211.    ostr[index++] = hun+'0';
  212.   }
  213.  if ((ten)||(hun)||(thou))
  214.   {
  215.    ostr[index++] = ten+'0';
  216.   }
  217.  ostr[index++] = one+'0';
  218.  ostr[index] = 0;
  219.  strcat(ostr,&fstr[7]);
  220. }
  221.  
  222.  
  223. void
  224. Initialize (void)
  225. {
  226.   mycnt1 = mycnt2 = 0;
  227. #if defined CHESSTOOL || defined XBOARD
  228. #ifndef SYSV
  229. /*  setlinebuf (stdout);*/
  230. #else
  231. /*  setvbuf (stdout, NULL, _IOLBF, BUFSIZ);*/
  232. #endif
  233. /*  printf (CP[43]);*/        /*Chess*/
  234.   if (!TCflag && (MaxResponseTime == 0))
  235.     MaxResponseTime = 15L*100L;
  236. #endif /* CHESSTOOL */
  237. }
  238.  
  239.  
  240. void DoAMove(void);
  241.  
  242. void DoAMove()
  243. {
  244.  char astr[40];
  245.  int r,c,l;
  246.  char piece;
  247.  
  248.       r = mvstr[0][3] - '1';
  249.       c = mvstr[0][2] - 'a';
  250.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  251.       if (color[l] == neutral)
  252.        {
  253.     //DisplayBeep(0L);
  254.         //Delay(25L);
  255.     //DisplayBeep(0L);
  256.         //Delay(25L);
  257.     //DisplayBeep(0L);
  258.         //Delay(25L);
  259.         piece = ' ';
  260.        }
  261.       else if (color[l] == white)
  262.         piece = qxx[board[l]]; /* white are lower case pieces */
  263.       else
  264.         piece = pxx[board[l]]; /* black are upper case pieces */
  265.   if (computer == black)
  266.    {
  267.     mysprintf(astr,"%d: ",GameCnt>>1);
  268.     strcat(astr,mvstr[0]);
  269.    }
  270.   else
  271.    {
  272.     mysprintf(astr,"%d: ",(GameCnt+1)>>1);   
  273.     strcat(astr,mvstr[0]);
  274.    }
  275.   DisplayComputerMove(astr);
  276.   if (piece != ' ')
  277.    AnimateAmigaMove(mvstr[0],piece);
  278. }
  279. void
  280. ExitChess (void)
  281. {
  282. /*  signal (SIGTERM, SIG_IGN);*/
  283.   ListGame (0L);
  284. #ifdef AMIGA
  285.   if (AmigaStarted)
  286.    AmigaShutDown();
  287. #endif
  288.   exit (0);
  289. }
  290.  
  291. #ifndef MSDOS            /* never called!!! */
  292. #ifndef AMIGA
  293. void
  294. Die (int sig)
  295. {
  296.   char s[80];
  297.  
  298.   ShowMessage (CP[31]);        /*Abort?*/
  299.   scanz ("%s", s);
  300.   if (strcmp (s, CP[210]) == 0)    /*yes*/
  301.     ExitChess ();
  302. }
  303. #endif
  304. #endif /* MSDOS */
  305.  
  306. void
  307. TerminateSearch (int sig)
  308. {
  309. #ifdef MSDOS
  310.   sig++;            /* shut up the compiler */
  311. #endif /* MSDOS */
  312.   if (!flag.timeout)
  313.     flag.musttimeout = true;
  314.   flag.bothsides = false;
  315. }
  316.  
  317.  
  318. void
  319. help (void)
  320. {
  321. #ifndef AMIGA
  322.   ClrScreen ();
  323.   /*printz ("CHESS command summary\n");*/
  324.   printz (CP[40]);
  325.   printz ("----------------------------------------------------------------\n");
  326.   /*printz ("g1f3      move from g1 to f3      quit      Exit Chess\n");*/
  327.   printz (CP[158]);
  328.   /*printz ("Nf3       move knight to f3       beep      turn %s\n", (flag.beep) ? "off" : "on");*/
  329.   printz (CP[86], (flag.beep) ? CP[92] : CP[93]);
  330.   /*printz ("a7a8q     promote pawn to queen\n");*/
  331.   printz (CP[128], (flag.material) ? CP[92] : CP[93]);
  332.   /*printz ("o-o       castle king side        easy      turn %s\n", (flag.easy) ? "off" : "on");*/
  333.   printz (CP[173], (flag.easy) ? CP[92] : CP[93]);
  334.   /*printz ("o-o-o     castle queen side       hash      turn %s\n", (flag.hash) ? "off" : "on");*/
  335.   printz (CP[174], (flag.hash) ? CP[92] : CP[93]);
  336.   /*printz ("bd        redraw board            reverse   board display\n");*/
  337.   printz (CP[130]);
  338.   /*printz ("list      game to chess.lst       book      turn %s used %d of %d\n", (Book) ? "off" : "on", bookcount, BOOKSIZE);*/
  339.   printz (CP[170], (Book) ? CP[92] : CP[93], bookcount, BOOKSIZE);
  340.   /*printz ("undo      undo last ply           remove    take back a move\n");*/
  341.   printz (CP[200]);
  342.   /*printz ("edit      edit board              force     enter game moves\n");*/
  343.   printz (CP[153]);
  344.   /*printz ("switch    sides with computer     both      computer match\n");*/
  345.   printz (CP[194]);
  346.   /*printz ("white     computer plays white    black     computer plays black\n");*/
  347.   printz (CP[202]);
  348.   /*printz ("depth     set search depth        clock     set time control\n");*/
  349.   printz (CP[149]);
  350.   /*printz ("post      principle variation     hint      suggest a move\n");*/
  351.   printz (CP[177]);
  352.   /*printz ("save      game to file            get       game from file\n");*/
  353.   printz (CP[188]);
  354.   /*printz ("random    randomize play          new       start new game\n");*/
  355.   printz (CP[181]);
  356.   printz ("----------------------------------------------------------------\n");
  357.   /*printz ("Computer: %-12s Opponent:            %s\n",*/
  358.   printz (CP[46],
  359.       ColorStr[computer], ColorStr[opponent]);
  360.   /*printz ("Depth:    %-12d Response time:       %d sec\n",*/
  361.   printz (CP[51],
  362.       MaxSearchDepth, MaxResponseTime/100);
  363.   /*printz ("Random:   %-12s Easy mode:           %s\n",*/
  364.   printz (CP[99],
  365.       (dither) ? CP[93] : CP[92], (flag.easy) ? CP[93] : CP[92]);
  366.   /*printz ("Beep:     %-12s Transposition file: %s\n",*/
  367.   printz (CP[36],
  368.       (flag.beep) ? CP[93] : CP[92], (flag.hash) ? CP[93] : CP[92]);
  369.   /*printz ("Time Control %s %d moves %d seconds %d opr %d depth\n", (TCflag) ? "ON" : "OFF",*/
  370.   printz (CP[110], (TCflag) ? CP[93] : CP[92],
  371.       TimeControl.moves[white], TimeControl.clock[white] / 100, OperatorTime, MaxSearchDepth);
  372.   signal (SIGINT, TerminateSearch);
  373. #ifndef MSDOS
  374.   signal (SIGQUIT, TerminateSearch);
  375. #endif /* MSDOS */
  376. #endif
  377. }
  378.  
  379. void
  380. EditBoard (void)
  381.  
  382. /*
  383.  * Set up a board position. Pieces are entered by typing the piece followed
  384.  * by the location. For example, Nf3 will place a knight on square f3.
  385.  */
  386.  
  387. {
  388.   INTSIZE a, r, c, sq, i, found;
  389.   int tmpcolor;
  390.   char s[80];
  391.  
  392.   flag.regularstart = false;
  393.   if (thinkahead)
  394.    {
  395.     flag.back = true;
  396.     while (thinkahead)
  397.      {
  398.       Delay(20L);
  399.      }
  400.    }
  401.   Book = 0;
  402. #ifndef AMIGA
  403.   /*printz (".   exit to main\n");*/
  404.   printz (CP[29]);
  405.   /*printz ("#   clear board\n");*/
  406.   printz (CP[28]);
  407.   /*printz ("c   change sides\n");*/
  408.   printz (CP[136]);
  409.   /*printz ("enter piece & location: \n");*/
  410.   printz (CP[155]);
  411. #else
  412.   if (!OpenAmigaEditWindow())
  413.    { /* open the window which will give us back text string */
  414.     DisplayBeep(0L);
  415.     Delay(25L);
  416.     DisplayBeep(0L);
  417.     return;
  418.    }
  419. #endif
  420.  
  421.   a = tmpcolor = white;
  422.   do
  423.     {
  424.       GetEditText(s,&tmpcolor); /* amiga routine to get the command from user */
  425.       found=0;
  426.       if (s[0] == CP[28][0])    /*#*/
  427.     for (sq = 0; sq < 64; sq++)
  428.       {
  429.         board[sq] = no_piece;
  430.         color[sq] = neutral;
  431.       }
  432.       if (a != tmpcolor)    /*c*/
  433.     a = otherside[a];
  434.       c = s[1] - 'a';
  435.       r = s[2] - '1';
  436.       if ((c >= 0) && (c < 8) && (r >= 0) && (r < 8))
  437.     {
  438.       sq = locn (r, c);
  439.       color[sq] = a;
  440.       board[sq] = no_piece;
  441.       for (i = no_piece; i <= king; i++)
  442.         if ((s[0] == pxx[i]) || (s[0] == qxx[i]))
  443.           {
  444.         board[sq] = i;
  445.         found=1;
  446.         break;
  447.           }
  448.       if ((found==0)||(board[sq] == no_piece)) color[sq] = neutral;    
  449.     }
  450.   } while (s[0] != CP[29][0]);
  451.   for (sq = 0; sq < 64; sq++)
  452.     Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  453.   CloseAmigaEditWindow(); /* Closes the edit window */
  454.   GameCnt = 0;
  455.   Game50 = 1;
  456.   ISZERO = 1;
  457.   ZeroRPT ();
  458.   Sdepth = 0;
  459.   InitializeStats ();
  460.   MoveMem128(board,amigaboard);
  461.   MoveMem128(color,amigacolor);
  462.   DrawAmigaBoard();
  463. }
  464.  
  465. void
  466. SetupBoard (void)
  467.  
  468. /*
  469.  * Compatibility with Unix chess and the nchesstool. Set up a board position.
  470.  * Eight lines of eight characters are used to setup the board. a8-h8 is the
  471.  * first line. Black pieces are  represented  by  uppercase characters.
  472.  */
  473.  
  474. {
  475. #ifdef AMIGA
  476. return;
  477. #else
  478.   INTSIZE r, c, sq, i;
  479.   char ch;
  480.   char s[80];
  481.  
  482.   NewGame ();
  483.  
  484.   gets (s);            /* skip "setup" command */
  485.   for (r = 7; r >= 0; r--)
  486.     {
  487.       gets (s);
  488.       for (c = 0; c <= 7; c++)
  489.     {
  490.       ch = s[c];
  491.       sq = locn (r, c);
  492.       color[sq] = neutral;
  493.       board[sq] = no_piece;
  494.       for (i = no_piece; i <= king; i++)
  495.         if (ch == pxx[i])
  496.           {
  497.         color[sq] = black;
  498.         board[sq] = i;
  499.         break;
  500.           }
  501.         else if (ch == qxx[i])
  502.           {
  503.         color[sq] = white;
  504.         board[sq] = i;
  505.         break;
  506.           }
  507.     }
  508.     }
  509.   for (sq = 0; sq < 64; sq++)
  510.     Mvboard[sq] = ((board[sq] != Stboard[sq]) ? 10 : 0);
  511.   InitializeStats ();
  512.   ClrScreen ();
  513.   UpdateDisplay (0, 0, 1, 0);
  514.   /*printz ("Setup successful\n");*/
  515.   printz (CP[106]);
  516. #endif
  517. }
  518.  
  519.  
  520. void
  521. ShowDepth (char ch)
  522. {
  523. #ifdef MSDOS
  524.   ch++;                /* shut up the compiler */
  525. #endif /* MSDOS */
  526. }
  527.  
  528.  
  529. void
  530. ShowLine (INTSIZE unsigned int *bstline,char *astr)
  531. {
  532.  
  533.       algbr ((INTSIZE) (bstline[1] >> 8), (INTSIZE) (bstline[1] & 0xFF), false);
  534.       strcpy (astr,mvstr[0]);
  535. }
  536.  
  537. void
  538. ShowResults (INTSIZE int score, INTSIZE unsigned int *bstline, char ch)
  539. {
  540.  char astr[64];
  541.  char nstr[16];
  542.  
  543. #if !defined CHESSTOOL
  544. /*printf("GameCnt = %d PrevDepth = %d\n",GameCnt,GameList[GameCnt-1].depth);*/
  545.   if ((!flag.easy)&&(ThinkAheadDepth)&&(TCflag)&&(GameCnt > 1)&&(Sdepth > 2))
  546.    { /* check for lookahead abort */
  547.     if ((Sdepth >= ThinkAheadDepth)&&(Sdepth >= GameList[GameCnt-1].depth)&&
  548.         (Sdepth > GlobalTgtDepth)&&(global_tmp_score >= (previous_score-25)))
  549.      { /* a chance I may want to abort search here */
  550.         if (!flag.musttimeout)
  551.          { /* not already aborted */
  552.           if ((ThinkInARow < 4)||(Sdepth > ThinkAheadDepth))
  553.            { /* max 4 times in a row */
  554.             flag.musttimeout = true;
  555.             if (Sdepth == ThinkAheadDepth)
  556.              ThinkInARow++;
  557.             else /* you thought past thinkaheaddepth */
  558.              ThinkInARow = 0;
  559.            }
  560.          }
  561.      }
  562.    }
  563.   if (flag.post)
  564.     {
  565.       ElapsedTime (2);
  566.       mysprintf3(astr,"D%d S%d ", Sdepth, score);
  567.       ShowLine (bstline,nstr);
  568.       strcat(astr,nstr);
  569.       ShowMessage(astr);
  570.     }
  571. #else
  572.   REG int i;
  573.  
  574.   MSCORE = score;
  575.   MV[30] = ch;
  576.   for (i = 1; bstline[i] > 0; i++)
  577.     {
  578.       MV[i] = bstline[i];
  579.     } MV[i] = 0;
  580. #endif /* CHESSTOOL */
  581. }
  582.  
  583. void
  584. SearchStartStuff (INTSIZE int side)
  585. {
  586.  unsigned long numsecs;
  587.  char astr[64];
  588.  
  589. //  signal (SIGINT, TerminateSearch);
  590. //#ifndef MSDOS
  591. //  signal (SIGQUIT, TerminateSearch);
  592. //#endif /* MSDOS */
  593. #if !defined CHESSTOOL
  594. /*#ifndef AMIGA*/
  595.   if (flag.post)
  596.     {
  597.       numsecs = (ResponseTime*2L+51L)/100L;
  598.       if (TCflag)
  599.        mysprintf4(astr,"Tgt:%d secs  ", numsecs);
  600.       else
  601.        mysprintf4(astr,"Tgt:%d ply   ", MaxSearchDepth);
  602.       ShowMessage(astr);
  603.     }
  604. /*#endif*/
  605. #endif /* CHESSTOOL */
  606. }
  607. void
  608. OutputMove (cstring)
  609. char *cstring;
  610. {
  611.  int r,c,l;
  612.  char astr[40];
  613.  char piece;
  614.  
  615. #ifdef DEBUG11
  616.   if (1)
  617.     {
  618.       FILE *D;
  619.       extern unsigned INTSIZE int PrVar[];
  620.       char d[80];
  621.       int r, c, l, i;
  622.       D = fopen ("/tmp/DEBUGA", "a+");
  623.       fprintf (D, "inout move is %s\n", mvstr[0]);
  624.       strcpy (d, mvstr[0]);
  625.       for (i = 1; PrVar[i] > 0; i++)
  626.     {
  627.       algbr ((INTSIZE) (PrVar[i] >> 8), (INTSIZE) (PrVar[i] & 0xFF), false);
  628.       fprintf (D, "%5s ", mvstr[0]);
  629.     }
  630.       fprintf (D, "\n");
  631.  
  632.       fprintf (D, "\n current board is\n");
  633.       for (r = 7; r >= 0; r--)
  634.     {
  635.       for (c = 0; c <= 7; c++)
  636.         {
  637.           l = locn (r, c);
  638.           if (color[l] == neutral)
  639.         fprintf (D, " -");
  640.           else if (color[l] == white)
  641.         fprintf (D, " %c", qxx[board[l]]);
  642.           else
  643.         fprintf (D, " %c", pxx[board[l]]);
  644.         }
  645.       fprintf (D, "\n");
  646.     }
  647.       fprintf (D, "\n");
  648.       fclose (D);
  649.       strcpy (mvstr[0], d);
  650.     }
  651. #endif
  652. if(flag.illegal){
  653.  IllegalMove = 1;
  654.  strcpy(IllegalString,CP[225]);
  655.  return;
  656. }
  657. if (mvstr[0][0] == '\0') goto nomove;
  658. #ifndef AMIGA
  659. #if defined CHESSTOOL
  660.   if (computer == black)
  661.     printz ("%d. ... %s\n", GameCnt, mvstr[0]);
  662.   else
  663.     printz ("%d. %s\n", ++mycnt1, mvstr[0]);
  664. #else
  665. #ifdef XBOARD
  666.   printz ("%d. ... %s\n", ++mycnt1, mvstr[0]);
  667. #else
  668.   printz ("%d. ... %s\n", ++mycnt1, mvstr[0]);
  669. #endif
  670. #endif /* CHESSTOOL */
  671. #endif /* amiga */
  672. #ifdef notdef
  673.   if (flag.post)
  674.     {
  675.       REG int i;
  676.  
  677.       printz (" %6d%c ", MSCORE, MV[30]);
  678.       for (i = 1; MV[i] > 0; i++)
  679.     {
  680.       algbr ((INTSIZE) (MV[i] >> 8), (INTSIZE) (MV[i] & 0xFF), false);
  681.       printz ("%5s ", mvstr[0]);
  682.     }
  683.     }
  684.   printz ("\n");
  685. #endif
  686. nomove:
  687.   if ((root->flags & draw)||(root->score == -9999)||
  688.       (root->score == 9998)) goto summary;
  689. #if !defined CHESSTOOL
  690.   if (flag.post)
  691.     {
  692.       INTSIZE h, l, t;
  693.  
  694.       h = TREE;
  695.       l = 0;
  696.       t = TREE >> 1;
  697.       while (l != t)
  698.     {
  699.       if (Tree[t].f || Tree[t].t)
  700.         l = t;
  701.       else
  702.         h = t;
  703.       t = (l + h) >> 1;
  704.     }
  705. #ifndef AMIGA
  706.       /*printf ("Nodes %ld Tree %d Eval %ld Rate %ld RS high %ld low %ld\n",*/
  707.       printf (CP[89],
  708.            NodeCnt, t, EvalNodes, (et) ? (NodeCnt / (et / 100)) : 0, reminus, replus);
  709.       /*printf ("Hin/Hout/Coll/Fin/Fout = %ld/%ld/%ld/%ld/%ld\n",*/
  710.       printf (CP[71],
  711.            HashAdd, HashCnt, THashCol, HashCol, FHashAdd, FHashCnt);
  712. #else /* print out thinking on amiga */
  713. #endif
  714.     }
  715.   UpdateDisplay (root->f, root->t, 0, root->flags);
  716. #ifndef AMIGA
  717.   /*printf ("My move is: %s\n", mvstr[0]);*/
  718.  
  719.   printz (CP[83], mvstr[0]);
  720. #else
  721.       r = mvstr[0][3] - '1';
  722.       c = mvstr[0][2] - 'a';
  723.       l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  724.       if (color[l] == neutral)
  725.        {
  726.     //DisplayBeep(0L);
  727.         //Delay(25L);
  728.     //DisplayBeep(0L);
  729.         //Delay(25L);
  730.     //DisplayBeep(0L);
  731.         //Delay(25L);
  732.         piece = ' ';
  733.        }
  734.       else if (color[l] == white)
  735.         piece = qxx[board[l]]; /* white are lower case pieces */
  736.       else
  737.         piece = pxx[board[l]]; /* black are upper case pieces */
  738.   if (computer == black)
  739.    {
  740.     mysprintf(astr,"%d: ",GameCnt>>1);
  741.     strcat(astr,mvstr[0]);
  742.    }
  743.   else
  744.    {
  745.     mysprintf(astr,"%d: ",(GameCnt+1)>>1);   
  746.     strcat(astr,mvstr[0]);
  747.    }
  748.   DisplayComputerMove(astr);
  749.   if (piece != ' ')
  750.    AnimateAmigaMove(mvstr[0],piece);
  751. #endif
  752.   if ((flag.beep)&&(!flag.bothsides))
  753.    {
  754.     DisplayBeep(0L);
  755.    }
  756. #endif /* CHESSTOOL */
  757.  summary:
  758.   if (root->flags & draw)
  759.     /*    printf ("Drawn game!\n");*/
  760.    {
  761.     /*printz (CP[57]);*/
  762.     DrawnGame = 1;
  763.    }
  764.   else if (root->score == -9999)
  765.    {
  766.     Mate = 1;
  767.     strcpy(MateString,ColorStr[opponent]);
  768.     strcat(MateString," mates!");
  769. /*    printz("%s mates!\n",ColorStr[opponent]);*/
  770.    }
  771.   else if (root->score == 9998)
  772.    {
  773.     Mate = 1;
  774.     DoAMove();
  775.     if (flag.bothsides)
  776.      {
  777.       strcpy(MateString,ColorStr[computer^1]);
  778.       strcat(MateString," mates!");
  779.      }
  780.     else
  781.      {
  782.       strcpy(MateString,ColorStr[computer]);
  783.       strcat(MateString," mates!");
  784.      }
  785. /*    printz("%s mates!\n",ColorStr[computer]);*/
  786.    }
  787. #if !defined CHESSTOOL && !defined XBOARD
  788. #ifdef VERYBUGGY
  789.   else if (root->score < -9000)
  790.     /*printf("%s has a forced mate!\n",ColorStr[opponent]);*/
  791.   else if (root->score > 9000)
  792.     /*printf("%s has a forced mate!\n",ColorStr[computer]);*/
  793. #endif /*VERYBUGGY*/
  794. #endif /* CHESSTOOL */
  795. }
  796.  
  797. void
  798. ClrScreen (void)
  799. {
  800. #if !defined CHESSTOOL && !defined XBOARD && !defined AMIGA
  801.   printz ("\n");
  802. #endif
  803. #ifdef AMIGA
  804. #endif
  805. }
  806.  
  807. void
  808. UpdateDisplay (INTSIZE int f, INTSIZE int t, INTSIZE int redraw, INTSIZE int isspec)
  809. {
  810.  
  811. #ifndef AMIGA
  812.   INTSIZE r, c, l, m;
  813. #endif
  814.  
  815.   if (redraw && !chesstool)
  816.     {
  817. #ifndef AMIGA /* text clock and etc display */
  818.       printz ("\n");
  819.       r = TimeControl.clock[white] / 6000;
  820.       c = (TimeControl.clock[white] % 6000) / 100;
  821.       l = TimeControl.clock[black] / 6000;
  822.       m = (TimeControl.clock[black] % 6000) / 100;
  823.       /*printz ("White %d:%02d  Black %d:%02d\n", r, c, l, m);*/
  824.       printz (CP[116], r, c, l, m);
  825.       printz ("\n");
  826.       for (r = 7; r >= 0; r--)
  827.     {
  828.       for (c = 0; c <= 7; c++)
  829.         {
  830.           l = ((flag.reverse) ? locn (7 - r, 7 - c) : locn (r, c));
  831.           if (color[l] == neutral)
  832.         printz (" -");
  833.           else if (color[l] == white)
  834.         printz (" %c", qxx[board[l]]);
  835.           else
  836.         printz (" %c", pxx[board[l]]);
  837.         }
  838.       printz ("\n");
  839.     }
  840.       printz ("\n");
  841. #else /* Update intution board on the Amiga */
  842. #endif
  843.     }
  844. }
  845.  
  846. void
  847. skip ()
  848. {
  849.   while (*InPtr != ' ')
  850.     InPtr++;
  851.   while (*InPtr == ' ')
  852.     InPtr++;
  853. }
  854. void
  855. skipb ()
  856. {
  857.   while (*InPtr == ' ')
  858.     InPtr++;
  859. }
  860.  
  861. #ifndef AMIGA
  862. void
  863. ShowMessage (char *s)
  864. {
  865. #ifndef AMIGA
  866.   printf("%s\n", s);
  867. #else /* write this msg on the intuition msg screen */
  868.   DisplayComputerMove(s);
  869. #endif
  870. }
  871.  
  872. #endif
  873.  
  874. void
  875. ShowSidetoMove (void)
  876. {
  877. }
  878.  
  879. void
  880. PromptForMove (void)
  881. {
  882. #if !defined CHESSTOOL && !defined XBOARD && !defined AMIGA
  883.   /*printz ("\nYour move is? ");*/
  884.   printz (CP[124]);
  885. #endif /* CHESSTOOL */
  886. }
  887.  
  888.  
  889. void
  890. ShowCurrentMove (INTSIZE int pnt, INTSIZE int f, INTSIZE int t)
  891. {
  892. #ifdef MSDOS
  893.   f++;
  894.   t++;
  895.   pnt++;            /* shut up the compiler */
  896. #endif /* MSDOS */
  897. }
  898.  
  899. void
  900. ChangeAlphaWindow (void)
  901. {
  902. #ifndef AMIGA
  903.   printz ("WAwindow: ");
  904.   scanz ("%hd", &WAwindow);
  905.   printz ("BAwindow: ");
  906.   scanz ("%hd", &BAwindow);
  907. #endif
  908. }
  909.  
  910.  
  911. void
  912. ChangeBetaWindow (void)
  913. {
  914. #ifndef AMIGA
  915.   printz ("WBwindow: ");
  916.   scanz ("%hd", &WBwindow);
  917.   printz ("BBwindow: ");
  918.   scanz ("%hd", &BBwindow);
  919. #endif
  920. }
  921.  
  922. void
  923. GiveHint (void)
  924. {
  925.   if (hint)
  926.     {
  927.       algbr2 ((INTSIZE) (hint >> 8), (INTSIZE) (hint & 0xFF), false);
  928.       strcpy(HintString,"Hint : ");
  929.       strcat(HintString,mvstrhint[0]);
  930.     }
  931.   else
  932.     strcpy (HintString,"No idea..");
  933. #ifndef AMIGA
  934. printf(HintString);
  935. #else
  936. DisplayComputerMove(HintString);
  937. #endif
  938. }
  939.  
  940. void
  941. SelectLevel (timestring)
  942. char *timestring;
  943. {
  944.   int tmp;
  945.   char T[64], *p, *q;
  946.  
  947. #ifndef AMIGA
  948.   printz (CP[61]);
  949.   scanz ("%hd %s", &TCmoves, T);
  950. #else
  951. #ifndef LONGINTS2
  952.   sscanf(timestring,"%hd %s",&TCmoves,T);
  953. #else
  954.   sscanf(timestring,"%d %s",&TCmoves,T);
  955. #endif
  956. #endif
  957.   for (p = T; *p == ' '; p++) ;
  958.   TCminutes = strtol (p, &q, 10);
  959.   TCadd = 0;
  960.   if (TCminutes < 1)
  961.    TCminutes = 1;
  962.   if (TCmoves < 1)
  963.    TCmoves = 1;
  964. //  if ((TCminutes/TCmoves) > 0)
  965. //   {
  966.     EnableMoveNow();
  967. //   }
  968. //  else
  969. //   {
  970. //    DisableMoveNow();
  971. //   }
  972.   if (*q == ':')
  973.     TCseconds = strtol (q + 1, (char **) NULL, 10);
  974.   else
  975.     TCseconds = 0;
  976. #ifdef OPERATORTIME
  977.   printz (CP[94]);
  978.   scanz ("%hd", &OperatorTime);
  979. #endif
  980.   if (TCmoves == 0) {
  981.     TCflag = false;
  982.     MaxResponseTime = TCminutes*60L*100L + TCseconds*100L;
  983.     TCminutes = TCseconds = 0;
  984.   } else {
  985.     TCflag = true;
  986.     MaxResponseTime = 0;
  987.     MaxSearchDepth = MAXDEPTH - 1;
  988.   }
  989.   SetTimeControl ();
  990. #ifdef AMIGA
  991.   tmp = player;
  992.   player = white;
  993.   UpdateClocks();
  994.   player = black;
  995.   UpdateClocks();
  996.   player = tmp;
  997. #endif
  998. }
  999.  
  1000. #ifdef DEBUG
  1001. void
  1002. ChangeDbLev (void)
  1003. {
  1004.   printz (CP[146]);
  1005.   scanz ("%hd", &debuglevel);
  1006. }
  1007.  
  1008. #endif /* DEBUG */
  1009.  
  1010. void
  1011. ChangeSearchDepth (void)
  1012. {
  1013.  int Old;
  1014.  
  1015.  Old = MaxSearchDepth;
  1016. #ifndef AMIGA
  1017.   printz ("depth= ");
  1018.   scanz ("%hd", &MaxSearchDepth);
  1019. #else
  1020.   MaxSearchDepth = SetAmigaDepth();
  1021. #endif
  1022.   if (MaxSearchDepth)
  1023.    {
  1024.     TCflag = !(MaxSearchDepth > 0);
  1025.     if (MaxSearchDepth > 2)
  1026.      EnableMoveNow();
  1027.    }
  1028.   else
  1029.    MaxSearchDepth = Old;
  1030. }
  1031.  
  1032. void ChangeHashDepth (void)
  1033. {
  1034. #ifndef AMIGA
  1035.   printz ("hashdepth= ");
  1036.   scanz ("%hd", &HashDepth);
  1037.   printz ("MoveLimit= ");
  1038.   scanz ("%hd", &HashMoveLimit);
  1039. #endif
  1040. }
  1041.  
  1042. void
  1043. SetContempt (void)
  1044. {
  1045. #ifndef AMIGA
  1046.   printz ("contempt= ");
  1047.   scanz ("%hd", &contempt);
  1048. #endif
  1049. }
  1050.  
  1051. void
  1052. ChangeXwindow (void)
  1053. {
  1054. #ifndef AMIGA
  1055.   printz ("xwndw= ");
  1056.   scanz ("%hd", &xwndw);
  1057. #endif
  1058. }
  1059.  
  1060. #ifdef DEBUGG
  1061. void
  1062. ShowPostnValue (INTSIZE int sq)
  1063.  
  1064. /*
  1065.  * must have called ExaminePosition() first
  1066.  */
  1067.  
  1068. {
  1069.   char astr[80];
  1070.   INTSIZE score;
  1071.  
  1072.   score = ScorePosition (color[sq]);
  1073.   if (color[sq] != neutral){
  1074.     sprintf (astr,"%3d%c ", svalue[sq],(color[sq] == black)?'b':'w');}
  1075.   else
  1076.     sprintf(astr," *   ");
  1077.   ShowMessage(astr);
  1078. }
  1079.  
  1080. void
  1081. DoDebug (void)
  1082. {
  1083. #ifndef AMIGA
  1084.   INTSIZE c, p, sq, tp, tc, tsq, score,j,k;
  1085.   char s[40];
  1086.  
  1087.   ExaminePosition ();
  1088.   ShowMessage (CP[65]);
  1089.   scanz ("%s", s);
  1090.   c = neutral;
  1091.   if (s[0] == CP[9][0] || s[0] == CP[9][1])     /* w W*/ c = white;
  1092.   if (s[0] == CP[9][2] || s[0] == CP[9][3])     /*b B*/ c = black;
  1093.   for (p = king; p > no_piece; p--)
  1094.     if ((s[1] == pxx[p]) || (s[1] == qxx[p])) break;
  1095.   if(p > no_piece)
  1096.   for(j=7;j>=0;j--){
  1097.   for(k=0;k<8;k++){
  1098.       sq=j*8+k;
  1099.       tp = board[sq];
  1100.       tc = color[sq];
  1101.       board[sq] = p;
  1102.       color[sq] = c;
  1103.       tsq = PieceList[c][1];
  1104.       PieceList[c][1] = sq;
  1105.       ShowPostnValue (sq);
  1106.       PieceList[c][1] = tsq;
  1107.       board[sq] = tp;
  1108.       color[sq] = tc;
  1109.     }
  1110.       printz("\n");
  1111.     }
  1112.   score = ScorePosition (opponent);
  1113.   printz (CP[103], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  1114. #endif
  1115. }
  1116.  
  1117. void
  1118. DoTable (INTSIZE table[64])
  1119. {
  1120.   char astr[16];
  1121.   INTSIZE  sq,j,k;
  1122.   ExaminePosition ();
  1123.   for(j=7;j>=0;j--){
  1124.   for(k=0;k<8;k++){
  1125.     sq=j*8+k;
  1126.     sprintf (astr,"%3d ", table[sq]);
  1127.     ShowMessage(astr);
  1128.   }
  1129. }
  1130. }
  1131.  
  1132. void
  1133. ShowPostnValues (void)
  1134. {
  1135.   INTSIZE sq, score,j,k;
  1136.   char astr[64];
  1137.  
  1138.   ExaminePosition ();
  1139.   for(j=7;j>=0;j--){
  1140.   for(k=0;k<8;k++){
  1141.   sq=j*8+k;
  1142.     ShowPostnValue (sq);
  1143.   }
  1144.   }
  1145.   score = ScorePosition (opponent);
  1146.  sprintf (astr,CP[103], score, mtl[computer], pscore[computer], mtl[opponent],pscore[opponent]);
  1147.  ShowMessage(astr);
  1148.  sprintf(astr,"hung white %d hung black %d\n",hung[white],hung[black]);
  1149.  ShowMessage(astr);
  1150. }
  1151.  
  1152. #endif
  1153.